//
//  Statuscell.swift
//  SinaWeibo25
//
//  Created by apple on 16/3/15.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit
class Statuscell: UITableViewCell {
    //模型数据
    var status: Status? {
        didSet {
            view.status = status
            //如果是转发微博的话 就给转发微博数据模型赋值
            if let re = status?.retweeted_status {
                retweeted.retweetedstatus = re
            } else {
                retweeted.retweetedstatus = nil
            }
        }
    }

    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        //设置选中状态
        selectionStyle = .None

        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    MARK: 设置UI
    private func setUI() {
//      backgroundColor = UIColor.yellowColor()
      contentView.addSubview(view)
      contentView.addSubview(bottomview)
      contentView.addSubview(retweeted)
        
        view.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
//            make.height.equalTo(100)
        }
        
        bottomview.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.top.equalTo(retweeted.snp_bottom)
            make.height.equalTo(36)
        }
        
        retweeted.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(view.snp_bottom)
            make.left.right.equalTo(view)
        }
        //开启自动布局之后 所有的frame布局就会自动失效
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.right.top.equalTo(self)
            make.bottom.equalTo(bottomview.snp_bottom)
        }

    
    }
    private lazy var view: Statusview = Statusview()
    
    private lazy var bottomview: StatusBottom = StatusBottom()
    
    private lazy var retweeted: StatusRetweetView = StatusRetweetView()
    
}
